package timing.ukulele.portal.mapper;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import timing.ukulele.portal.persistent.AntRoleMenu;
import timing.ukulele.portal.persistent.SysRoleMenuPermission;
import timing.ukulele.portal.persistent.SysRoleResource;

import java.util.List;
import java.util.Set;

@Mapper
@Repository
public interface AntRoleMenuMapper {

    @Select("select role_id as roleId,menu_id as menuId from ant_role_menu where role_id = #{roleId}")
    List<AntRoleMenu> selectRoleMenu(@Param("roleId") Long roleId);

    @Select("<script>" +
            "select distinct menu_id as menuId from ant_role_menu where role_id in (<foreach collection='roleIds' item='item' index='index' separator=','> #{item}</foreach>)"
            + "</script>")
    Set<Long> selectRoleMenuByIds(@Param("roleIds") List<Long> roleIds);

    @Delete("delete from ant_role_menu where role_id = #{roleId}")
    void deleteRoleMenu(@Param("roleId") Long roleId);

    @Insert("<script>" + "insert into ant_role_menu values <foreach collection='list' item='item' index='index' separator=','>(#{item.roleId},#{item.menuId},#{item.tenantId})</foreach>" + "</script>")
    void batchAddRoleMenu(List<AntRoleMenu> list);

    //###==========角色菜单权限==========###//

    @Select("select permission_id as permissionId, menu_id as menuId from sys_role_menu_permission where role_id = #{roleId}")
    List<SysRoleMenuPermission> getRolePermission(@Param("roleId") Long roleId);

    @Select("<script>" +
            "select permission_id as permissionId, menu_id as menuId from sys_role_menu_permission where role_id in (<foreach collection='roleIds' item='item' index='index' separator=','> #{item}</foreach>)"
            + "</script>")
    List<SysRoleMenuPermission> getRolePermissionByIds(@Param("roleIds") List<Long> roleIds);

    @Insert("<script>" + "insert into sys_role_menu_permission values <foreach collection='list' item='item' index='index' separator=','>(#{item.roleId},#{item.menuId},#{item.permissionId},#{item.tenantId})</foreach>" + "</script>")
    void batchAddRolePermission(List<SysRoleMenuPermission> list);

    @Delete("delete from sys_role_menu_permission where role_id=#{roleId}")
    void deleteRolePermission(@Param("roleId") Long roleId);

}
